#include "FrogSketcher.h"

#include <sstream>

FrogSketcher::FrogSketcher(Frog* frog)
{
	this->frog = frog;
	Color* lineColor = this->frog->getLineColor();
	Color* backgroundColor = this->frog->getElementColor();
	Texture* texture = this->frog->getTexture();
	Position* position = this->frog->getPosition();
	float radius = this->frog->getRadius();

	if(texture != NULL)
	{
		for(int angle = 0; angle < 360; angle += ROTATE_ANGLE)
		{
			string key;
			stringstream out;
			out << angle;
			key = "frog|angle:"+out.str();
			if(!SketcherHelper::getInstance()->containsCache(key))
			{
				SketcherHelper::getInstance()->addCachedCircle(key, radius, texture, lineColor, angle + 35);
			}
		}
	}
}

FrogSketcher::~FrogSketcher(void)
{
}

void FrogSketcher::draw()
{
	Color* lineColor = this->frog->getLineColor();
	Color* backgroundColor = this->frog->getElementColor();
	Texture* texture = this->frog->getTexture();
	Position* position = this->frog->getPosition();
	float radius = this->frog->getRadius();

	if(texture != NULL)
	{
		int angle = this->frog->getAngle();
		while((angle % ROTATE_ANGLE) != 0)
		{
			angle++;
		}

		string key;
		stringstream out;
		out << angle;
		key = "frog|angle:"+out.str();
		SketcherHelper::getInstance()->drawCachedCircle(key, position);
	}
	else
	{
		SketcherHelper::getInstance()->drawCircle(position, radius, backgroundColor, lineColor);
	}
}
